home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / GuiLib / Task / c++ / GuiTask < prev    next >
Text File  |  2003-02-14  |  4KB  |  117 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #include "GuiTask.h"
  39. #include "ERROR.h"
  40. #include "GuiRegister.h"
  41. #include "swis.h"
  42. #include "GuiWimp.h"
  43.  
  44. const char*       init_resource_directory;
  45. int               init_wimp_version;
  46. int*              init_wimp_messages;
  47. int*              init_toolbox_events;
  48.  
  49. //**********************************************************************
  50.  
  51. void guiTaskInitialise(const char* resource_dir,int wimp_version,
  52.                          int *wimp_mess,int *tbox_events)
  53. {
  54.   init_resource_directory=resource_dir;
  55.   init_wimp_version=wimp_version;
  56.   init_toolbox_events=tbox_events;
  57.   init_wimp_messages=wimp_mess;
  58.   guiTask();
  59. }
  60.  
  61.  
  62. //**********************************************************************
  63.  
  64. GuiTask& guiTask()
  65. {
  66.   static GuiTask t;
  67.   return t;
  68. }
  69.  
  70. //**********************************************************************
  71.  
  72. GuiTask::GuiTask()
  73. {
  74.   static int wimp_messages;
  75.   static int toolbox_events;
  76.   if (init_resource_directory==0) ERROR("Toolbox not Initialised");
  77.   ERROR(_swix(Toolbox_Initialise,_INR(0,6) | _OUTR(0,2),0,init_wimp_version,
  78.                       ((init_wimp_messages == GUI_TASK_ALL_MESSAGES)?&wimp_messages:init_wimp_messages),
  79.                       ((init_toolbox_events == GUI_TASK_ALL_MESSAGES)?&toolbox_events:init_toolbox_events),
  80.                        (char *)init_resource_directory,&m_messages,
  81.                        &m_id_block, &m_wimp_version, &m_handle,(void**)&m_sprite_area));
  82.  
  83.   GuiRegister::initialise(m_id_block);
  84.  
  85.   m_resource_directory=init_resource_directory;
  86.  
  87.   _kernel_swi_regs reg;
  88.   reg.r[0]=0;
  89.   reg.r[1]=0;
  90.   ERROR(_kernel_swi(Toolbox_GetSysInfo,®,®));
  91.   m_name.resize(reg.r[2]-1);
  92.   if (m_name.size()==reg.r[2]-1)
  93.      {
  94.      reg.r[0]=0;
  95.      reg.r[1]=(int)m_name.data();
  96.      ERROR(_kernel_swi(Toolbox_GetSysInfo,®,®));
  97.      }
  98. }
  99.  
  100. //**********************************************************************
  101.  
  102. void GuiTask::raiseEvent(GuiObject& ob,GuiToolboxEvent& event,GuiComponentId cid)
  103. {
  104.   _swix(Toolbox_RaiseToolboxEvent,_INR(0,3),0,ob.id(),cid,&event);
  105. }
  106.  
  107. //**********************************************************************
  108.  
  109. const char* GuiTask::lookup(const char* token, const char* p0,const char* p1,
  110.                                               const char* p2,const char* p3)
  111. {
  112.   static char buf[512];
  113.   if (_swix(MessageTrans_Lookup,_INR(0,7),
  114.             &m_messages,token,buf,sizeof(buf),p0,p1,p2,p3)==0) return buf;
  115.   return "";
  116. }
  117.